package LeetCodeHot100TopInterview;

public class Q121_StockMaxProfit {

    //股票问题第一问
    //一天买一天卖
    public int maxProfit(int[] prices) {
        if (prices == null || prices.length == 0){
            return 0;
        }
        int min = prices[0];
        int ans = 0;
        for (int i = 0; i < prices.length; i++) {
            ans = Math.max(ans, prices[i] - min);
            min = Math.min(min, prices[i]);
        }
        return ans;
    }

}
